// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>

namespace cantor::unresolved {

    class UnresolvedUserSpec;
    class UnresolvedPrivLevel;

    class UnresolvedPrivStmt : public UnresolvedVisitor<UnresolvedPrivStmt> {
    public:
        UnresolvedPrivStmt(const cantor::pb::ast::PrivStmt &node) :instance(node) {
        }

        ~UnresolvedPrivStmt() override = default;

        const pb::Location& location_impl() const {
            return  instance.location();
        }

        const pb::Status &error_status_impl() const {
            return  instance.status();
        }

        size_t privs() const {
            return instance.privs_size();
        }

        cantor::pb::ast::PrivType privs(int index) const {
            return instance.privs(index);
        }

        bool has_priv_level() const {
            return instance.has_priv_level();
        }

        UnresolvedPrivLevel priv_level() const;

        size_t  specs_size() const {
            return instance.specs_size();
        }

        UnresolvedUserSpec spes(int index) const;

        bool with_grant(bool flag = false) const {
            if (instance.has_with_grant()) {
                return instance.with_grant();
            }
            return flag;
        }

        std::string_view ns_name(std::string_view value = std::string_view{}) const {
            if (instance.has_namespace_name()) {
                return instance.namespace_name();
            }
            return value;
        }

        const cantor::pb::ast::PrivStmt &instance;
    };
} // namespace cantor::unresolved
